package com.abacus.pos.base


import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/**
 * Created by lin on 20-4-15.
 */
open class BaseViewModel : ViewModel() {


    private val viewEvents = MutableLiveData<Int>()


    private val uiScope = viewModelScope

    fun launch(block: suspend CoroutineScope.() -> Unit) {
        uiScope.launch {
            block()
        }
    }

    fun initEvent() {
        viewEvents.value = null
    }

    fun Int.publish() {
        viewEvents.value = this
    }

}